package cn.bdqn.page2;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * 打印消费详单,打印出来的消费详单不能显示
 */
public class Print {
	// 因为所有的方法都需要DOM树
	static Document document = null;
	static Element root = null;

	// 打印出来的详单
	public void printDoc(String phone) throws IOException, DocumentException {
		SAXReader reader = new SAXReader();
		String path1 = System.getProperty("user.dir");
		path1 = path1.replace("\\", "/");
		String path = path1.concat("/").concat("消费详单.xml");
		File file = new File(path);
		file.createNewFile();
		Writer writer = new FileWriter(file);
		BufferedWriter bw = new BufferedWriter(writer);
		bw.newLine();
		bw.write("**********" + phone + "消费记录**********");
		bw.newLine();
		bw.write("序号\t类型\t数据（通话（条）/上网（GB）/短信（条）");
		bw.newLine();
		document = reader.read("UserMessage.xml");
		root = (Element) document.getRootElement();
		Iterator itUser = root.elementIterator();
		while (itUser.hasNext()) {
			Element user = (Element) itUser.next();
			int num = 1;
			if (user.attributeValue("record") != null) {
				for (int i = 0; true; i++) {
					bw.write(num + user.attributeValue("record"));
					bw.newLine();
				}
			}

		}

	}
}